California
# extract Texas's rows with STATEFP 48
california_map <- us[us$STATEFP %in% c("06"),]
democrat$GEOID <- formatC(democrat$GEOID, width = 5, format = "d", flag = "0")
# merge California unemployment rate and democrat party information
california<-merge(california_map,unemploy,by=c("GEOID"))
california<-merge(california,democrat,by=c("GEOID"))
# year 2008
ca_2008 <- california[which(california$year==2008),]
# year 2012
ca_2012 <- california[which(california$year==2012),]
# year 2016
ca_2016 <- california[which(california$year==2016),]
# 2008 California Democratic Vote Percentage
title_7 <- tags$p(tags$style("p {font-size:12px}"),
tags$b("2008 California Democratic Vote Percentage"))
popup_dat <- paste0("<strong>County: </strong>",
ca_2008$county.x,
"<br><strong>Percent of Vote: </strong>",
paste(round(100*ca_2008$percent, 2), "%", sep=""))
pal<-colorQuantile("Blues", NULL, n = 10)
map_7 <- leaflet(data = ca_2008,
options = leafletOptions(attributionControl=FALSE)) %>%
addTiles()%>%
setView(lng = -120, lat = 36, zoom = 4.5) %>%
addPolygons(fillColor = ~pal(percent),
fillOpacity = 1,
color = "#BDBDC3",
weight = 1,
popup = popup_dat
) %>%
addLegend("bottomleft", pal = pal, values = ~percent,
title = "Percent of Vote",
opacity = 0.6)%>%
addControl(title_7, position = "topright" )%>%
addProviderTiles(providers$CartoDB.Positron)
## Warning: sf layer has inconsistent datum (+proj=longlat +datum=NAD83 +no_defs).
## Need '+proj=longlat +datum=WGS84'
## Warning in RColorBrewer::brewer.pal(max(3, n), palette): n too large, allowed maximum for palette Blues is 9
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(max(3, n), palette): n too large, allowed maximum for palette Blues is 9
## Returning the palette you asked for with that many colors
#map_7
# 2008 California Unemployment Rate
title_8 <- tags$p(tags$style("p {font-size:12px}"),
tags$b("2008 California Unemployment Rate"))
popup_dat <- paste0("<strong>County: </strong>",
ca_2008$county.x,
"<br><strong>Unemployment Rate: </strong>",
ca_2008$Unemployment_rate_2008)
pal<-colorQuantile("Oranges", NULL, n = 10)
map_8 <- leaflet(data = ca_2008,options = leafletOptions(
attributionControl=FALSE)) %>%
addTiles() %>%
setView(lng = -120, lat = 36, zoom = 4.5) %>%
addPolygons(fillColor = ~pal(Unemployment_rate_2008),
fillOpacity = 1,
color = "#BDBDC3",
weight = 1,
popup = popup_dat
) %>%
addLegend("bottomleft", pal = pal, values = ~Unemployment_rate_2008,
title = "Unemployment Rate",
opacity = 0.6)%>%
addControl(title_8, position = "topright" )%>%
addProviderTiles(providers$CartoDB.Positron)
## Warning: sf layer has inconsistent datum (+proj=longlat +datum=NAD83 +no_defs).
## Need '+proj=longlat +datum=WGS84'
## Warning in RColorBrewer::brewer.pal(max(3, n), palette): n too large, allowed maximum for palette Oranges is 9
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(max(3, n), palette): n too large, allowed maximum for palette Oranges is 9
## Returning the palette you asked for with that many colors
# map_8
# 2012 California Democratic Vote Percentage
title_9 <- tags$p(tags$style("p {font-size:12px}"),
tags$b("2012 California Democratic Vote Percentage"))
popup_dat <- paste0("<strong>County: </strong>",
ca_2012$county.x,
"<br><strong>Percent of Vote: </strong>",
paste(round(100*ca_2012$percent, 2), "%", sep=""))
pal<-colorQuantile("Blues", NULL, n = 10)
map_9 <- leaflet(data = ca_2012,
options = leafletOptions(attributionControl=FALSE)) %>%
addTiles()%>%
setView(lng = -120, lat = 36, zoom = 4.5) %>%
addPolygons(fillColor = ~pal(percent),
fillOpacity = 1,
color = "#BDBDC3",
weight = 1,
popup = popup_dat
) %>%
#addLegend("bottomleft", pal = pal, values = ~percent,
# title = "Percent of Vote",
# opacity = 0.8)%>%
addControl(title_9, position = "topright" )%>%
addProviderTiles(providers$CartoDB.Positron)
## Warning: sf layer has inconsistent datum (+proj=longlat +datum=NAD83 +no_defs).
## Need '+proj=longlat +datum=WGS84'
## Warning in RColorBrewer::brewer.pal(max(3, n), palette): n too large, allowed maximum for palette Blues is 9
## Returning the palette you asked for with that many colors
#map_9
# 2012 California Unemployment Rate
title_10 <- tags$p(tags$style("p {font-size:12px}"),
tags$b("2012 California Unemployment Rate"))
popup_dat <- paste0("<strong>County: </strong>",
ca_2012$county.x,
"<br><strong>Unemployment Rate: </strong>",
ca_2012$Unemployment_rate_2012)
pal<-colorQuantile("Oranges", NULL, n = 10)
map_10 <- leaflet(data = ca_2012,options = leafletOptions(
attributionControl=FALSE)) %>%
addTiles() %>%
setView(lng = -120, lat = 36, zoom = 4.5) %>%
addPolygons(fillColor = ~pal(Unemployment_rate_2012),
fillOpacity = 1,
color = "#BDBDC3",
weight = 1,
popup = popup_dat
) %>%
#addLegend("bottomleft", pal = pal, values = ~Unemployment_rate_2012,
#title = "Unemployment Rate",
#opacity = 0.8)%>%
addControl(title_10, position = "topright" )%>%
addProviderTiles(providers$CartoDB.Positron)
## Warning: sf layer has inconsistent datum (+proj=longlat +datum=NAD83 +no_defs).
## Need '+proj=longlat +datum=WGS84'
## Warning in RColorBrewer::brewer.pal(max(3, n), palette): n too large, allowed maximum for palette Oranges is 9
## Returning the palette you asked for with that many colors
# map_10
# 2016 California Democratic Vote Percentage
title_11 <- tags$p(tags$style("p {font-size:12px}"),
tags$b("2016 California Democratic Vote Percentage"))
popup_dat <- paste0("<strong>County: </strong>",
ca_2016$county.x,
"<br><strong>Percent of Vote: </strong>",
paste(round(100*ca_2016$percent, 2), "%", sep=""))
pal<-colorQuantile("Blues", NULL, n = 10)
map_11 <- leaflet(data = ca_2016,
options = leafletOptions(attributionControl=FALSE)) %>%
addTiles()%>%
setView(lng = -120, lat = 36, zoom = 4.5) %>%
addPolygons(fillColor = ~pal(percent),
fillOpacity = 1,
color = "#BDBDC3",
weight = 1,
popup = popup_dat
) %>%
#addLegend("bottomleft", pal = pal, values = ~percent,
# title = "Percent of Vote",
# opacity = 0.8)%>%
addControl(title_11, position = "topright" )%>%
addProviderTiles(providers$CartoDB.Positron)
## Warning: sf layer has inconsistent datum (+proj=longlat +datum=NAD83 +no_defs).
## Need '+proj=longlat +datum=WGS84'
## Warning in RColorBrewer::brewer.pal(max(3, n), palette): n too large, allowed maximum for palette Blues is 9
## Returning the palette you asked for with that many colors
#map_11
# 2016 California Unemployment Rate
title_12 <- tags$p(tags$style("p {font-size:12px}"),
tags$b("2016 California Unemployment Rate"))
popup_dat <- paste0("<strong>County: </strong>",
ca_2016$county.x,
"<br><strong>Unemployment Rate: </strong>",
ca_2016$Unemployment_rate_2016)
pal<-colorQuantile("Oranges", NULL, n = 10)
map_12 <- leaflet(data = ca_2016,options = leafletOptions(
attributionControl=FALSE)) %>%
addTiles() %>%
setView(lng = -120, lat = 36, zoom = 4.5) %>%
addPolygons(fillColor = ~pal(Unemployment_rate_2016),
fillOpacity = 1,
color = "#BDBDC3",
weight = 1,
popup = popup_dat
) %>%
#addLegend("bottomleft", pal = pal, values = ~Unemployment_rate_2016,
# title = "Unemployment Rate",
# opacity = 0.8)%>%
addControl(title_12, position = "topright" )%>%
addProviderTiles(providers$CartoDB.Positron)
## Warning: sf layer has inconsistent datum (+proj=longlat +datum=NAD83 +no_defs).
## Need '+proj=longlat +datum=WGS84'
## Warning in RColorBrewer::brewer.pal(max(3, n), palette): n too large, allowed maximum for palette Oranges is 9
## Returning the palette you asked for with that many colors
# map_12
sync(list(map_7, map_9, map_11, map_8, map_10, map_12),ncol=3)